home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_185 / include / iff / ilbm.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  12KB  |  296 lines

  1. #ifndef ILBM_H
  2. #define ILBM_H
  3. /*----------------------------------------------------------------------*
  4.  * ILBM.H  Definitions for InterLeaved BitMap raster image.     1/23/86
  5.  *   09/88 - added CAMG, CCRT, and CRNG typedefs and macros  (cs)
  6.  *
  7.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  8.  * This software is in the public domain.
  9.  *
  10.  * This version for the Commodore-Amiga computer.
  11.  *----------------------------------------------------------------------*/
  12. #ifndef COMPILER_H
  13. #include "iff/compiler.h"
  14. #endif
  15.  
  16. #ifndef GRAPHICS_GFX_H
  17. #include "graphics/gfx.h"
  18. #endif
  19.  
  20. #include "iff/iff.h"
  21.  
  22. #define ID_ILBM MakeID('I','L','B','M')
  23. #define ID_BMHD MakeID('B','M','H','D')
  24. #define ID_CMAP MakeID('C','M','A','P')
  25. #define ID_GRAB MakeID('G','R','A','B')
  26. #define ID_DEST MakeID('D','E','S','T')
  27. #define ID_SPRT MakeID('S','P','R','T')
  28. #define ID_CAMG MakeID('C','A','M','G')
  29. #define ID_CRNG MakeID('C','R','N','G')
  30. #define ID_CCRT MakeID('C','C','R','T')
  31. #define ID_BODY MakeID('B','O','D','Y')
  32.  
  33.  
  34.  
  35. /* ---------- BitMapHeader ---------------------------------------------*/
  36.  
  37. typedef UBYTE Masking;      /* Choice of masking technique.*/
  38. #define mskNone                 0
  39. #define mskHasMask              1
  40. #define mskHasTransparentColor  2
  41. #define mskLasso                3
  42.  
  43. typedef UBYTE Compression;   /* Choice of compression algorithm applied to
  44.      * each row of the source and mask planes. "cmpByteRun1" is the byte run
  45.      * encoding generated by Mac's PackBits. See Packer.h . */
  46. #define cmpNone      0
  47. #define cmpByteRun1  1
  48.  
  49. /* Aspect ratios: The proper fraction xAspect/yAspect represents the pixel
  50.  * aspect ratio pixel_width/pixel_height.
  51.  *
  52.  * For the 4 Amiga display modes:
  53.  *   320 x 200: 10/11  (these pixels are taller than they are wide)
  54.  *   320 x 400: 20/11
  55.  *   640 x 200:  5/11
  56.  *   640 x 400: 10/11      */
  57. #define x320x200Aspect 10
  58. #define y320x200Aspect 11
  59. #define x320x400Aspect 20
  60. #define y320x400Aspect 11
  61. #define x640x200Aspect  5
  62. #define y640x200Aspect 11
  63. #define x640x400Aspect 10
  64. #define y640x400Aspect 11
  65.  
  66. /* A BitMapHeader is stored in a BMHD chunk. */
  67. typedef struct {
  68.     UWORD w, h;         /* raster width & height in pixels */
  69.     WORD  x, y;         /* position for this image */
  70.     UBYTE nPlanes;      /* # source bitplanes */
  71.     Masking masking;      /* masking technique */
  72.     Compression compression;   /* compression algoithm */
  73.     UBYTE pad1;         /* UNUSED.  For consistency, put 0 here.*/
  74.     UWORD transparentColor;   /* transparent "color number" */
  75.     UBYTE xAspect, yAspect;   /* aspect ratio, a rational number x/y */
  76.     WORD  pageWidth, pageHeight;  /* source "page" size in pixels */
  77.     } BitMapHeader;
  78.  
  79. /* RowBytes computes the number of bytes in a row, from the width in pixels.*/
  80. #define RowBytes(w)   (((w) + 15) >> 4 << 1)
  81.  
  82.  
  83. /* ---------- ColorRegister --------------------------------------------*/
  84. /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */
  85. typedef struct {
  86.     UBYTE red, green, blue;   /* MUST be UBYTEs so ">> 4" won't sign extend.*/
  87.     } ColorRegister;
  88.  
  89. /* Use this constant instead of sizeof(ColorRegister). */
  90. #define sizeofColorRegister  3
  91.  
  92. typedef WORD Color4;   /* Amiga RAM version of a color-register,
  93.           * with 4 bits each RGB in low 12 bits.*/
  94.  
  95. /* Maximum number of bitplanes in RAM. Current Amiga max w/dual playfield. */
  96. #define MaxAmDepth 6
  97.  
  98. /* ---------- Point2D --------------------------------------------------*/
  99. /* A Point2D is stored in a GRAB chunk. */
  100. typedef struct {
  101.     WORD x, y;      /* coordinates (pixels) */
  102.     } Point2D;
  103.  
  104. /* ---------- DestMerge ------------------------------------------------*/
  105. /* A DestMerge is stored in a DEST chunk. */
  106. typedef struct {
  107.     UBYTE depth;   /* # bitplanes in the original source */
  108.     UBYTE pad1;      /* UNUSED; for consistency store 0 here */
  109.     UWORD planePick;   /* how to scatter source bitplanes into destination */
  110.     UWORD planeOnOff;   /* default bitplane data for planePick */
  111.     UWORD planeMask;   /* selects which bitplanes to store into */
  112.     } DestMerge;
  113.  
  114. /* ---------- SpritePrecedence -----------------------------------------*/
  115. /* A SpritePrecedence is stored in a SPRT chunk. */
  116. typedef UWORD SpritePrecedence;
  117.  
  118. /* ---------- Camg Amiga Viewport Mode ---------------------------------*/
  119. /* A Commodore Amiga ViewPort->Modes is stored in a CAMG chunk. */
  120. /* The chunk's content is declared as a LONG. */
  121. typedef struct {
  122.    ULONG ViewModes;
  123.    } CamgChunk;
  124.  
  125. /* ---------- CRange cycling chunk -------------------------------------*/
  126. /* A CRange is store in a CRNG chunk. */
  127. typedef struct {
  128.     WORD  pad1;              /* reserved for future use; store 0 here */
  129.     WORD  rate;      /* 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 */
  130.     WORD  active;     /* bit0 set = active, bit 1 set = reverse */
  131.     UBYTE low, high;   /* lower and upper color registers selected */
  132.     } CRange;
  133.  
  134. /* ---------- Ccrt (Graphicraft) cycling chunk -------------------------*/
  135. /* A Ccrt is stored in a CCRT chunk. */
  136. typedef struct {
  137.    WORD  direction;  /* 0=don't cycle, 1=forward, -1=backwards */
  138.    UBYTE start;      /* range lower */
  139.    UBYTE end;        /* range upper */
  140.    LONG  seconds;    /* seconds between cycling */
  141.    LONG  microseconds; /* msecs between cycling */
  142.    WORD  pad;        /* future exp - store 0 here */
  143.    } CcrtChunk;
  144.  
  145.  
  146. /* ---------- ILBM Writer Support Routines -----------------------------*/
  147.  
  148. /* Note: Just call PutCk to write a BMHD, GRAB, DEST, SPRT, or CAMG
  149.  * chunk. As below. */
  150. #define PutBMHD(context, bmHdr)  \
  151.     PutCk(context, ID_BMHD, sizeof(BitMapHeader), (BYTE *)bmHdr)
  152. #define PutGRAB(context, point2D)  \
  153.     PutCk(context, ID_GRAB, sizeof(Point2D), (BYTE *)point2D)
  154. #define PutDEST(context, destMerge)  \
  155.     PutCk(context, ID_DEST, sizeof(DestMerge), (BYTE *)destMerge)
  156. #define PutSPRT(context, spritePrec)  \
  157.     PutCk(context, ID_SPRT, sizeof(SpritePrecedence), (BYTE *)spritePrec)
  158. #define PutCAMG(context, camg)  \
  159.     PutCk(context, ID_CAMG, sizeof(CamgChunk),(BYTE *)camg)
  160. #define PutCRNG(context, crng)  \
  161.     PutCk(context, ID_CRNG, sizeof(CRange),(BYTE *)crng)
  162. #define PutCCRT(context, ccrt)  \
  163.     PutCk(context, ID_CCRT, sizeof(CcrtChunk),(BYTE *)ccrt)
  164.  
  165. #ifdef FDwAT
  166.  
  167. /* Initialize a BitMapHeader record for a full-BitMap ILBM picture.
  168.  * This gets w, h, and nPlanes from the BitMap fields BytesPerRow, Rows, and
  169.  * Depth. It assumes you want  w = bitmap->BytesPerRow * 8 .
  170.  * CLIENT_ERROR if bitmap->BytesPerRow isn't even, as required by ILBM format.
  171.  *
  172.  * If (pageWidth, pageHeight) is (320, 200), (320, 400), (640, 200), or
  173.  * (640, 400) this sets (xAspect, yAspect) based on those 4 Amiga display
  174.  * modes. Otherwise, it sets them to (1, 1).
  175.  * 
  176.  * After calling this, store directly into the BitMapHeader if you want to
  177.  * override any settings, e.g. to make nPlanes smaller, to reduce w a little,
  178.  * or to set a position (x, y) other than (0, 0).*/
  179. extern IFFP InitBMHdr(BitMapHeader *, struct BitMap *,
  180.         /*  bmHdr,          bitmap  */
  181.      int,     int,         int,              WORD,      WORD);
  182.  /*  masking, compression, transparentColor, pageWidth, pageHeight */
  183.  /*  Masking, Compression, UWORD -- are the desired types, but get
  184.   *  compiler warnings if use them.               */
  185.  
  186. /* Output a CMAP chunk to an open FORM ILBM write context. */
  187. extern IFFP PutCMAP(GroupContext *, WORD *,   UBYTE);
  188.       /*  context,        colorMap, depth  */
  189.  
  190. /* This procedure outputs a BitMap as an ILBM's BODY chunk with
  191.  * bitplane and mask data. Compressed if bmHdr->compression == cmpByteRun1.
  192.  * If the "mask" argument isn't NULL, it merges in the mask plane, too.
  193.  * (A fancier routine could write a rectangular portion of an image.)
  194.  * This gets Planes (bitplane ptrs) from "bitmap".
  195.  *
  196.  * CLIENT_ERROR if bitmap->Rows != bmHdr->h, or if
  197.  * bitmap->BytesPerRow != RowBytes(bmHdr->w), or if
  198.  * bitmap->Depth < bmHdr->nPlanes, or if bmHdr->nPlanes > MaxAmDepth, or if
  199.  * bufsize < MaxPackedSize(bitmap->BytesPerRow), or if
  200.  * bmHdr->compression > cmpByteRun1. */
  201. extern IFFP PutBODY(
  202.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG);
  203.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  204.  
  205. #else /*not FDwAT*/
  206.  
  207. extern IFFP InitBMHdr();
  208. extern IFFP PutCMAP();
  209. extern IFFP PutBODY();
  210.  
  211. #endif FDwAT
  212.  
  213. /* ---------- ILBM Reader Support Routines -----------------------------*/
  214.  
  215. /* Note: Just call IFFReadBytes to read a BMHD, GRAB, DEST, SPRT, or CAMG
  216.  * chunk. As below. */
  217. #define GetBMHD(context, bmHdr)  \
  218.     IFFReadBytes(context, (BYTE *)bmHdr, sizeof(BitMapHeader))
  219.  
  220. #define GetGRAB(context, point2D)  \
  221.     IFFReadBytes(context, (BYTE *)point2D, sizeof(Point2D))
  222. #define GetDEST(context, destMerge)  \
  223.     IFFReadBytes(context, (BYTE *)destMerge, sizeof(DestMerge))
  224. #define GetSPRT(context, spritePrec)  \
  225.     IFFReadBytes(context, (BYTE *)spritePrec, sizeof(SpritePrecedence))
  226. #define GetCAMG(context, camg)  \
  227.     IFFReadBytes(context, (BYTE *)camg, sizeof(CamgChunk))
  228. #define GetCRNG(context, crng)  \
  229.     IFFReadBytes(context, (BYTE *)crng, sizeof(CRange))
  230. #define GetCCRT(context, ccrt)  \
  231.     IFFReadBytes(context, (BYTE *)ccrt, sizeof(CcrtChunk))
  232.  
  233.  
  234. /* GetBODY can handle a file with up to 16 planes plus a mask.*/
  235. #define MaxSrcPlanes 16+1
  236.  
  237. #ifdef FDwAT
  238.  
  239. /* Input a CMAP chunk from an open FORM ILBM read context.
  240.  * This converts to an Amiga color map: 4 bits each of red, green, blue packed
  241.  * into a 16 bit color register.
  242.  * pNColorRegs is passed in as a pointer to a UBYTE variable that holds
  243.  * the number of ColorRegisters the caller has space to hold. GetCMAP sets
  244.  * that variable to the number of color registers actually read.*/
  245. extern IFFP GetCMAP(GroupContext *, WORD *,   UBYTE *);
  246.       /*  context,        colorMap, pNColorRegs  */
  247.  
  248. /* GetBODY reads an ILBM's BODY into a client's bitmap, de-interleaving and
  249.  * decompressing.
  250.  *
  251.  * Caller should first compare bmHdr dimensions (rowWords, h, nPlanes) with
  252.  * bitmap dimensions, and consider reallocating the bitmap.
  253.  * If file has more bitplanes than bitmap, this reads first few planes (low
  254.  * order ones). If bitmap has more bitplanes, the last few are untouched.
  255.  * This reads the MIN(bmHdr->h, bitmap->Rows) rows, discarding the bottom
  256.  * part of the source or leaving the bottom part of the bitmap untouched.
  257.  *
  258.  * GetBODY returns CLIENT_ERROR if asked to perform a conversion it doesn't
  259.  * handle. It only understands compression algorithms cmpNone and cmpByteRun1.
  260.  * The filed row width (# words) must agree with bitmap->BytesPerRow.
  261.  *
  262.  * Caller should use bmHdr.w; GetBODY only uses it to compute the row width
  263.  * in words. Pixels to the right of bmHdr.w are not defined.
  264.  *
  265.  * [TBD] In the future, GetBODY could clip the stored image horizontally or
  266.  * fill (with transparentColor) untouched parts of the destination bitmap.
  267.  *
  268.  * GetBODY stores the mask plane, if any, in the buffer pointed to by mask.
  269.  * If mask == NULL, GetBODY will skip any mask plane. If
  270.  * (bmHdr.masking != mskHasMask) GetBODY just leaves the caller's mask alone.
  271.  *
  272.  * GetBODY needs a buffer large enough for two compressed rows.
  273.  * It returns CLIENT_ERROR if bufsize < 2 * MaxPackedSize(bmHdr.rowWords * 2).
  274.  *
  275.  * GetBODY can handle a file with up to MaxSrcPlanes planes. It returns
  276.  * CLIENT_ERROR if the file has more. (Could be due to a bum file, though.)
  277.  * If GetBODY fails, itt might've modified the client's bitmap. Sorry.*/
  278. extern IFFP GetBODY(
  279.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG);
  280.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  281.  
  282. /* [TBD] Add routine(s) to create masks when reading ILBMs whose
  283.  * masking != mskHasMask. For mskNone, create a rectangular mask. For
  284.  * mskHasTransparentColor, create a mask from transparentColor. For mskLasso,
  285.  * create an "auto mask" by filling transparent color from the edges. */
  286.  
  287. #else /*not FDwAT*/
  288.  
  289. extern IFFP GetCMAP();
  290. extern IFFP GetBODY();
  291.  
  292. #endif FDwAT
  293.  
  294. #endif ILBM_H
  295.  
  296.